package com.sfac.modules.account.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:唐琳的爹
 * @BelongsProject:hqyj_springboot
 * @BelongsPackage:com.sfac.modules.account.controller
 * @CreateTime:2022/8/27 10:41:59
 */
@Controller
@RequestMapping("/account")
public class AccountController {


    /**
     * 注册页面跳转
     * @param modelMap
     * @return
     */
    @GetMapping("/register")
    public String register(ModelMap modelMap){
        modelMap.addAttribute("template","account/register");
        return "index3";
    }


    /**
     * 登录页面跳转
     * @param modelMap
     * @return
     */
    @GetMapping("/login")
    public String login(ModelMap modelMap){
        modelMap.addAttribute("template","account/login");
        return "index3";
    }

    /**
     * 用户页面跳转
     * @return
     */
    @GetMapping("/users")
    @RequiresRoles(value = {"admin","manager"},logical = Logical.OR)
    public String getUsers(){
        return "index";
    }


    @GetMapping(value = "logout")
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "redirect:login";
    }
}
